layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;
    

    var tableIns = table.render({
    	elem: '#stateRecord',
        url : '/main/getBoxUseRecord?boxId='+$(".boxId").val(),
        cellMinWidth : 150,
        page : true,
        height : "full-125",
        limit : 10,
        limits : [10,15,20,25],
        id : "stateRecordTable",
        cols : [[
        	{ field: 'source', title: '平台',align: "center",templet: function(item){
        		if(item.source =="2"||item.source=="3"){
        			return '<span style="color:green;">微信</span>' 
        		}else if(item.source =="4"||item.source=="5"){
        			return  '<span style="color:#39a2ec;">支付宝</span>' 
        		}else{
        			return "恒铸管理系统";
        		}
        	}},
            {field: 'type', title: '操作', align:"center"},
            {field: 'usePerson', title: '存物ID/管理员',align:"center"},
            {field: 'isManager', title: '是否为管理员操作',align:"center",templet:function(f){
            	if(f.isManager == "是"){
            		return "<span class='layui-red'>是</span>"
            	}else{
            		return "<span>否</span>"
            	}
            } },
            {field: 'useTime', title: '时间', align:'center'}
        ]]
    });
    
	$(".layui-icon-refresh-3").on("click",function(){
   	 	location.reload();
	})
    
    $('#button').on('click', function(){
		  table.reload("stateRecordTable",{
			  page: {
				  curr: 1 //重新从第 1 页开始
			  },
			  where: {
				  startTime:begin,
				  endTime:end
			  }
		  })
	  });
    
    var begin,end
	  //执行一个laydate实例
	  laydate.render({
	    elem: '#begin' //指定元素
	    ,type:'datetime'
	    ,done: function(value, date, endDate){
		   	// console.log(value);
			begin=value //得到日期生成的值，如：2017-08-18
		}
	  });
	  laydate.render({
	    elem: '#end' //指定元素
	    ,type:'datetime'
	   ,done: function(value, date, endDate){
	   		// console.log(value);
	   		end=value //得到日期生成的值，如：2017-08-18
	   	}
	  });
})
